<?php

namespace app\common\model\marketing;

use addons\xyb\XypHelper;
use think\Model;


class Association extends Model
{

    // 表名
    protected $name = 'association';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    public static function getAdminLists()
    {
        $keyword = request()->param('keyword', '');
        $deadline = request()->param('deadline/a');
        $grant_status = request()->param('grant_status/a');
        $field = '';
        $query = self::field($field);
        if ($keyword) {
            $query->where(function ($query) use ($keyword) {
                $query->where('id', 'like', "%{$keyword}%")
                    ->whereOr('name', 'like', "%{$keyword}%")
                    ->whereOr('describe', 'like', "%{$keyword}%");
            });
        }
        if ($deadline_arr = XypHelper::stringToArray($deadline)) {
            $query->where('start_time','>',  XypHelper::getTimestamp($deadline_arr[0]))
                ->where('end_time','<',  XypHelper::getTimestamp($deadline_arr[1]));
        }
        if ($grant_status = XypHelper::stringToArray($grant_status)) {
            $query->whereIn('grant_status', $grant_status);
        }
        return $query->order('id desc')->paginate(10);
    }

}